package com.xncoding.rocketmq.Listener;

import com.xncoding.rocketmq.basic.Order;
import com.xncoding.rocketmq.constant.RocketConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer;
import org.springframework.stereotype.Component;

import java.util.List;

/***
* @description 顺序消息的监听器
* 1.只需要设置consumeMode= ConsumeMode.ORDERLY
* 2.发送方须要设置MessageQueueSelector
* @author luming
* @date 2021/4/24 17:05
* @throws
*/
@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = "ConsumerGroupB", topic = RocketConstant.TOPIC_ORDER,consumeMode= ConsumeMode.ORDERLY)
public class OrderMessageListener implements RocketMQListener<Order> {
    @Override
    public void onMessage(Order order) {
        //这里每个MessageQueue只会用一个线程去消费
        log.info("Received order message:{},current thread:{}",order,Thread.currentThread().getName());
    }
}
